package com.hanggold.endpoint.filter;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2019-07-25 17:15
 * @since
 **/
//@Component
public class EndpointServletRegistarationBean extends ServletRegistrationBean<EndpointServlet> {

    private EndpointServlet servlet;

    public EndpointServletRegistarationBean(EndpointServlet servlet) {
        super(servlet, "/myservlet/*");
        this.servlet = servlet;
    }

    @Override
    protected ServletRegistration.Dynamic addRegistration(String description, ServletContext servletContext) {
        String name = getServletName();
        return servletContext.addServlet(name, this.servlet);
    }

//    @Override
//    protected void configure(ServletRegistration.Dynamic registration) {
//        super.configure(registration);
////        String[] urlMapping = StringUtils.toStringArray(this.urlMappings);
////        if (urlMapping.length == 0 && this.alwaysMapUrl) {
////            urlMapping = DEFAULT_MAPPINGS;
////        }
////        if (!ObjectUtils.isEmpty(urlMapping)) {
////            registration.addMapping(urlMapping);
////        }
//        registration.addMapping("/myservlet");
//        registration.setLoadOnStartup(1);
////        if (this.multipartConfig != null) {
////            registration.setMultipartConfig(this.multipartConfig);
////        }
//    }

}
